package com.xbs.controller.admin;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.EmployeeEntity;
import com.xbs.service.content.AdminLoginService;
@WebServlet("/admin/login2")
public class Adminlogin1 extends BaseServlet{
	private boolean jg;
	private AdminLoginService as;
	private EmployeeEntity emp;
	private HashMap<String,Object> map;
	public Adminlogin1() {
		jg=true;
		as = new AdminLoginService();
		emp = new EmployeeEntity();
		map = new HashMap<>();
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取用户填写的账户和密码
		String name = req.getParameter("Email1");
		String pwd = req.getParameter("Password1");
		
		String error="";
		//服务器端验证是否为空
		if(name==null||name.isEmpty()){
			error="手机号不能为空";
			jg=false;
		}
		if(pwd==null||pwd.isEmpty()){
			error="密码不能为空";
			jg=false;
		}
		//从数据库中获取该用户的密码
		emp = as.selEmp(name);
		if(jg){
			//验证密码是否正确
			if(emp.getPwd().equals(pwd)){
				//获取该用户的姓名
				map.put("ename",emp.getEmpname());
				map.put("erole",emp.getEmprole());
				map.put("etel", emp.getEmptel());
				map.put("estore",emp.getEmpstore());
				map.put("status", 1);
				System.out.println("fdjsl");
				redirect("/admin/index",map);
			}else{
				error="账号或密码错误";
				req.setAttribute("error", error);
				forward("admin/basicSetting/AdminLogin");
			}
		}
		
		
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		forward("admin/basicSetting/AdminLogin");		
	}
}
